﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HAVTKPack
{


     public  class IsHeadScalarChanged
    {

        /// <summary>
        /// 判断单元的有效性标记数组是否发生变化
        /// </summary>
        /// <param name="oldScalar"></param>
        /// <param name="newScalar"></param>
        /// <returns></returns>
         public static bool IsHeadCellScalarChanged(List<double[,]> oldScalar, List<double[,]> newScalar)
        {
            if ((oldScalar == null && newScalar != null) || (oldScalar != null && newScalar == null))
            {
                return true;
            }
            if (oldScalar == null && newScalar == null)
            {
                return false;
            }
            if (oldScalar.Count != newScalar.Count)
            {
                return true;
            }
            if (oldScalar.Count == 0 && newScalar.Count == 0)
            {
                return false;
            }
            //两者 count 相等  并且不为0
            for (int i = 0; i < oldScalar.Count; i++)
            {
                if ((oldScalar[i] == null && newScalar[i] != null) || (oldScalar[i] != null && newScalar[i] == null))
                {
                    return true;
                }
                else if (oldScalar[i] != null && newScalar[i] != null)
                {

                    if ((oldScalar[i].GetLength(0) != newScalar[i].GetLength(0)) || (oldScalar[i].GetLength(1) != newScalar[i].GetLength(1)))
                    {
                        return true;
                    }
                    else
                    {
                        for (int rows = 0; rows < oldScalar[i].GetLength(0); rows++)
                        {
                            for (int cols = 0; cols < oldScalar[i].GetLength(1); cols++)
                            {
                                if (oldScalar[i][rows, cols] != newScalar[i][rows, cols])
                                {
                                    return true;
                                }
                            }

                        }
                    }


                }
            }


            return false;
        }


         public static bool IsLayerHeadScalarChanged(double[,] oldScalar, double[,] newScalar)
         {
             if ((oldScalar == null && newScalar != null) || (oldScalar != null && newScalar == null))
             {
                 return true;
             }
             if (oldScalar == null && newScalar == null)
             {
                 return false;
             }

             if (oldScalar.GetLength(0) != newScalar.GetLength(0) || oldScalar.GetLength(1) != newScalar.GetLength(1))
             {
                 return true;
             }
             else
             {
                 for (int rows = 0; rows < oldScalar .GetLength (0); rows++)
                 {
                     for (int cols  =  0; cols  < oldScalar .GetLength (1); cols ++)
                     {
                         if (oldScalar [rows ,cols ]!=newScalar [rows ,cols ])
                         {
                             return true;
                         }
                     }
                 }
             
             }

             return false;

         }





    }



}
